package gameframework;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;







public class RoTrung {
	//
	
	
	//toa do x cua ro trung
	
	public int x;
	// toa do y cua ro trung
	
	public int y;
	
	//hinh cua ro trung
	
	public BufferedImage Ro_Trung;
	
	
	//khu vuc di chuyen cua ro trung
	
	private int ro_trung_width;
	//toc do duy chuyen ro trung
	private int tocdo_x;
	//
	
	//
	public int ro_trung_height;
	
	public RoTrung(int giatrimoi_x,int giatrimoi_y){
		this.x=giatrimoi_x;
		this.y=giatrimoi_y;
		Initialize();
		LoadContent();
		
	}
	 private void Initialize()
	    {   
	        // X coordinate of the landing area is at 46% frame width.
	        //this.x = (int)(Framework.frameWidth * 0.46);
	        // Y coordinate of the landing area is at 86% frame height.
	       // this.y = (int)(Framework.frameHeight * 0.88);
		 tocdo_x=10;
	    }
	private void LoadContent()
	{
		try
        {
            URL loadhinhrotrung = this.getClass().getResource("/gameframework/resources/images/Ro.png");
            Ro_Trung = ImageIO.read(loadhinhrotrung);
            ro_trung_width = Ro_Trung.getWidth()/2;
            ro_trung_height=Ro_Trung.getHeight()/2;
        }
        catch (IOException ex) {
            Logger.getLogger(RoTrung.class.getName()).log(Level.SEVERE, null, ex);
        }
		
	}
	public void update()
	{
		
		 if(Canvas.keyboardKeyState(KeyEvent.VK_LEFT) && x>0)
		       
	            x -= tocdo_x;
		 if(Canvas.keyboardKeyState(KeyEvent.VK_RIGHT) && x<Framework.frameWidth-ro_trung_width*2)
			 	x += tocdo_x;
		 		
		 
		 
		// x-=tocdo_x;
	}
	
	public void Draw(Graphics2D g2d,Point mousePosition)
    {
		mousePosition.y=Framework.frameHeight-ro_trung_width;
        g2d.drawImage(Ro_Trung, mousePosition.x,y, null);
    }
	
	public void Draw2(Graphics2D g2d)
    {
		
        g2d.drawImage(Ro_Trung, x, y,null );
    }
	
	public void khoitao_lai(int x_re,int y_re)
	{
		this.x=x_re;
		this.y=y_re;
		
		
		this.tocdo_x=10;
	}
	
}
